package com.unnamed.b.atv.view;

import com.unnamed.b.atv.ResourceTable;
import ohos.agp.components.*;
import ohos.app.Context;

import static ohos.agp.components.ComponentContainer.LayoutConfig.MATCH_CONTENT;
import static ohos.agp.components.ComponentContainer.LayoutConfig.MATCH_PARENT;

/**
 * Created by Bogdan Melnychuk on 2/10/15.
 */
public class TreeNodeWrapperView extends DirectionalLayout {
    private ComponentContainer nodeContainer;
    private final int containerStyle;

    public TreeNodeWrapperView(Context context, int containerStyle) {
        super(context);
        this.containerStyle = containerStyle;
        init();
    }

    private void init() {
        setOrientation(DirectionalLayout.VERTICAL);
        setLayoutConfig(new LayoutConfig(MATCH_PARENT, MATCH_CONTENT));
        nodeContainer = new DependentLayout(getContext());
        nodeContainer.setLayoutConfig(new LayoutConfig(MATCH_PARENT, MATCH_CONTENT));
        nodeContainer.setId(ResourceTable.String_node_header);
        DirectionalLayout nodeItemsContainer = new DirectionalLayout(getContext(), null);
        nodeItemsContainer.setLayoutConfig(new LayoutConfig(MATCH_PARENT, MATCH_CONTENT));
        nodeItemsContainer.setPaddingLeft(60);
        nodeItemsContainer.setId(ResourceTable.String_node_items);
        nodeItemsContainer.setOrientation(DirectionalLayout.VERTICAL);
        nodeItemsContainer.setVisibility(Component.HIDE);
        addComponent(nodeContainer);
        addComponent(nodeItemsContainer);
    }

    public void insertNodeView(Component nodeView) {
        try {
            nodeContainer.addComponent(nodeView);
        } catch (Exception e) {
            throw new RuntimeException("Could not instantiate class " + e.getMessage());
        }
    }

    public ComponentContainer getNodeContainer() {
        return nodeContainer;
    }
}
